package com.ssm.blog.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.blog.dao.AdminUserDAO;
import com.ssm.blog.pojo.AdminUser;
import com.ssm.blog.service.AdminUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class AdminUserServiceImpl implements AdminUserService {

    @Autowired
    private AdminUserDAO adminUserDAO;


    @Override
    public PageInfo<AdminUser> getAdminUsers(AdminUser criteria, int page, int pageSize) {
        PageHelper.startPage(page, pageSize, "id desc");
        List<AdminUser> userList = adminUserDAO.getAdminUsers(criteria);
        PageInfo<AdminUser> pager = new PageInfo<>(userList);
        return pager;
    }

    @Override
    public void addAdminUser(AdminUser user) throws Exception {
        AdminUser count = adminUserDAO.getUserByEmail(user.getEmail());
        if (count != null) {
            throw new Exception("该邮箱已注册");
        }
        adminUserDAO.addAdminUser(user);
    }

    @Override
    public void updateAdminUser(AdminUser user) {
        adminUserDAO.updateAdminUser(user);
    }
}
